package lesson19;

import java.util.Scanner;

public class SecuredNotepad extends SimpleNotepad implements ISecuredNotepad
{
	private final String password;
	
	public SecuredNotepad(int numberOfPages, Scanner sc) 
	{
		super(numberOfPages, sc);
		System.out.println("Enter password:");
		String password = sc.nextLine();
		this.password = password;
	}
	
	@Override
	public boolean validatePassword() 
	{
		Scanner sc = new Scanner(System.in);
		System.out.println("Enter password: ");
		String password = sc.nextLine();
		return this.password.equals(password);
		
	}
	
	@Override
	public void addTextToPage(int numberOfPage, String text) 
	{
	
		if(validatePassword())
		{
			super.addTextToPage(numberOfPage, text);
		}
		else
		{
			System.out.println("Wrong password!");
		}
	}

	@Override
	public void changeTextOfPage(int numberOfPage, String text) 
	{
		
		if(validatePassword())
		{
			super.changeTextOfPage(numberOfPage, text);
		}
		else
		{
			System.out.println("Wrong password!");
		}
	}
	
	@Override
	public void deleteTextFromPage(Page selectedPage) 
	{
		if(validatePassword())
		{
			super.deleteTextFromPage(selectedPage);
		}
		else
		{
			System.out.println("Wrong password!");
		}
	}
	
	@Override
	public void printAllPages() 
	{
		if(validatePassword())
		{
			super.printAllPages();
		}
		else
		{
			System.out.println("Wrong password!");
		}
	}

}
